package com.example.springboot.demo.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author daifei
 * @date 2019/7/10
 */
@Service
@Slf4j
public class HelloServiceWithFallback {


    @HystrixCommand(fallbackMethod = "fallback")
    public String hello(String name) {
//        String responseEntity = restTemplate.getForObject("http://HELLOSERVICE/hello?name={1}", String.class, name);
//        log.info("hello service :{}", responseEntity);
//        return responseEntity;
        return 1/0 +"";
    }

    /**
     * 错误回调方法参数签名必须与原方法一致
     *
     * @param name
     * @return
     */
    public String fallback(String name, Throwable e) {
        log.info("这是造成服务降级的异常信息：{}",name, e);
        return "this is fallback message! ";
    }

}
